<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<select name="txt_parentid">
<?php 
  require_once("../conn/conn_db.php");  //包含数据库连接文件
  static $line="|--";  //声明静态变量
  GetProductType($conn, '0');  //调用函数

  function GetProductType($conn, $parentid) //定义函数，加载类别
  {
    global $line;  //声明全局静态变量
    global $parentid2;
    $sql = "select * from product_type where pt_parentid=".$parentid;
    $result = $conn->query($sql); //执行SQL语句
    if ($result->num_rows > 0) {
        while($row = $result->fetch_array())
      {
        echo "<option value='".$row['pt_id']."'".($parentid2 == $row['pt_id']? "selected":"")." >".$line.$row['pt_name']."</option>"; 
        $line .= "---";
        GetProductType($conn, $row['pt_id']);  //递归 调用
        $line  = substr($line,0,strlen($line) -3); 	
      }
    }
  }
?>
</select>
</body>
</html>